import {createWebHistory, createRouter} from 'vue-router'
import Board from "@/pages/Board/board.vue";
import errorview from "@/pages/404.vue";

const routes = [
    // 首页
    {
        path: '',
        name: 'layout',
        component:()=>import('@/pages/Layout/layout.vue'),
        meta:{
            title:'布局',
            isAuth:false,
            keepAlive:true
        },
        children:[
            {
                path: '',
                name: 'ImageQuery',
                component:()=>import('@/pages/Query/ImageQuery.vue'),
                meta:{
                    title:'图片查询',
                    isAuth:false,
                    keepAlive:true
                },
            },
            {
                path: '/AvatarQuery',
                name: 'AvatarQuery',
                component:()=>import('@/pages/Query/AvatarQuery.vue'),
                meta:{
                    title:'头像查询',
                    isAuth:false,
                    keepAlive:true
                },
            },
            {
                path: '/WatermarkQuery',
                name: 'WatermarkQuery',
                component:()=>import('@/pages/Query/WatermarkQuery.vue'),
                meta:{
                    title:'水印图片查询',
                    isAuth:false,
                    keepAlive:true
                },
            },
            {
                path: '/ResoureQuery',
                name: 'ResoureQuery',
                component:()=>import('@/pages/Query/ResoureQuery.vue'),
                meta:{
                    title:'资源查询',
                    isAuth:false,
                    keepAlive:true
                },
            },
            {
                path: '/APKQuery',
                name: 'APKQuery',
                component:()=>import('@/pages/Query/APKQuery.vue'),
                meta:{
                    title:'APK查询',
                    isAuth:false,
                    keepAlive:true
                },
            },
            {
                path: '/VideoQuery',
                name: 'VideoQuery',
                component:()=>import('@/pages/Query/VideoQuery.vue'),
                meta:{
                    title:'视频查询',
                    isAuth:false,
                    keepAlive:true
                },
            },
            {
                path: '/PolicySettings',
                name: 'PolicySettings',
                component:()=>import('@/pages/WorkBench/PolicySettings.vue'),
                meta:{
                    title:'策略设置',
                    isAuth:false,
                    keepAlive:true
                },
            }
        ]
    },
    // 看板首页
    {
        path: '/Board',
        component: Board,
        name:'Board',
        meta:{
            title:'看板',
            isAuth:true,
            keepAlive:true
        }
    },
    // 404页面
    {
        path: '/:pathMatch(.*)*',
        name: '404',
        component: errorview,
        meta:{
            title:'404',
            isAuth:false,
            keepAlive:true
        }
    },
]

const router = createRouter({
    history: createWebHistory(),
    routes
})
// 前置路由守卫
router.beforeEach((to, from, next)=>{
    // 验证是否需要用户登录
    if (to.meta.isAuth){
        // 设置为 标签栏的题目
        document.title = to.meta.title
        next() //放行操作: 必须调用 路由才能继续运行
    }
    else {
        // 设置为 标签栏的题目
        document.title = to.meta.title
        next() //放行操作: 必须调用 路由才能继续运行
    }
})

export default router